<template>
  <!-- 左侧菜单栏 -->
  <el-menu
    unique-opened
    :collapse="isCollapse"
    :default-active="$route.path"
    class="el-menu-vertical-demo"
    background-color="rgb(60,120,120)"
    text-color="#fff"
    active-text-color="rgb(152,251,252)"
    router
  >
    <!--是否水平折叠收起菜单 会影响这里字段的显示 -->
    <h3 v-show="isCollapse">Hotel</h3>
    <h3 v-show="!isCollapse">WuShan<br />酒店管理系统</h3>
    <hr />
    <el-menu-item
      :index="item.path"
      v-for="item in noChildren"
      :key="item.path"
      @click="clickMenu(item)"
    >
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <el-submenu index="index" v-for="(item, index) in hasChildren" :key="index">
      <template slot="title">
        <i :class="'el-icon-' + item.icon"></i>
        <span>{{ item.label }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item
          :index="subItem.path"
          v-for="(subItem, subIndex) in item.children"
          :key="subIndex"
          @click="clickMenu(subItem)"
        >
          {{ subItem.label }}
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>
//封装的左侧导航菜单
import navmenu from "../config/navmenu.js";
export default {
  //计算属性
  computed: {
    //没有子菜单
    noChildren() {
      return this.menu.filter(item => !item.children);
    },
    //有子菜单
    hasChildren() {
      return this.menu.filter(item => item.children);
    },
    isCollapse() {
      // 这里的数据就是从vuex取得
      return this.$store.state.tab.isCollapse;
    }
  },
  data() {
    return {
      //获取菜单栏数据并赋值给menu
      menu: navmenu
    };
  },
  methods: {
    clickMenu(item) {
      this.$store.commit("selectMenu", item);
    }
  }
};
</script>
<style scoped>
.el-menu {
  height: 100%;
  border: none;
}
h3 {
  color: hsl(0, 0%, 100%);
  text-align: center;
  line-height: 30px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
hr {
  height: 1px;
  border: none;
  border-top: 5px groove #ffffff;
}
</style>
